﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QMetaProperty>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    car=new Car;
    //connect(car,&Car::moneyChanged,this,&MainWindow::moneyChanged);
    //car->setMoney(1000);
    //qDebug()<<car->getMoney();

//    car->setProperty("money",9000);
//    qDebug()<<car->property("money").toString();

//    const QMetaObject*ob=car->metaObject();
//    int count=ob->propertyCount();
//    for(int i=0;i<count;i++)
//    {
//        QMetaProperty mp=ob->property(i);
//        qDebug()<<mp.name();
//    }

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::moneyChanged(int money)
{
    qDebug()<<"价格改动了:现在是:"<<money<<endl;
}


void MainWindow::on_pushButton_clicked()
{
    car->setProperty(ui->lineEdit->text().toStdString().c_str(),ui->lineEdit_2->text());
    auto names=car->dynamicPropertyNames();
    int count=names.count();
    qDebug()<<count;

    for(auto names:names)
    {
        qDebug()<<names<<car->property(names).toString();
    }
}
